﻿@{
    Layout = null;
}
@using CNKI.TPI.Web.Search.Model;
@using CNKI.TPI.Web.Base;
<script>
    function modityInfo(dbid, dbcode, fields,papertype,timeflage) {
        $("#dbid").val(dbid);
        //设置后街时间序列的选中状态
        if (timeflage == 1) {
            $("#timecheck").attr("checked", "checked");
        }
        else {
            $("#timecheck").removeAttr("checked", "checked");
        }
        //设置单选按钮的选中状态
        if(papertype!="")
            $("input[name='type'][value=" + papertype + "]").attr("checked", true);
        else
            $("input[name='type'][value=0]").attr("checked", true);

        showSubmit();
        $(".ulfield").empty();  //右侧字段
        if (fields != "") {
            var arrayfields = fields.toString().split(',');
            var len = arrayfields.length;
            if (len > 0) {
                for (var j = 0; j < len; j++) {
                    var listr = " <li>  <label class=\"f-label block\">" +
                   " <input type=\"checkbox\" class=\"f-checkbox\" value='" + arrayfields[j] + "' />" + arrayfields[j] + "</label></li>";
                    $(".ulfield").append(listr);
                }

            }
        }
        //左侧待选字段
        $.ajax({  
            type: "GET",
            url: timestamp("@Html.Raw(Url.Action("GetNumField", "Admin_Submit"))"),
            beforeSend: function () { $(".talkDivBgField").show(); },
            data: { "DbCode": dbcode },
            success: function (msg) {
                var obj = eval(msg);
                $(".wrapR-c-box-b-left ul").empty();
                if (obj != null && obj.length > 0) {
                    for (var i = 0; i < obj.length; i++) {
                        var listr = " <li> <label class=\"f-label block\">" +
                       " <input type=\"checkbox\" class=\"f-checkboxL\"  onclick=\"leftcheck(this)\" value='" + obj[i].Field + "' />" + obj[i].Field + "</label></li>";
                        $(".wrapR-c-box-b-left ul").append(listr);
                    }
                }
            },
            error: function (e)
            { }

        })
        if ($("input[name='type']:checked").val() == 2) {
            $(".talkDivBgField").hide();
        }
    }

    function closeSubmit() {
        $(".talkDivBg").hide();
        $(".submitnum").hide();
    }
    function showSubmit() {
        $(".talkDivBg").show();
        $(".submitnum").show();
    }
    function saveSubmitNumber() {
        var paperType = $("input[name='type']:checked").val();
        var selectfield = [];
        var timecheck = 0;
        if (paperType == 2)//获取设置字段的值
        {
            $('.wrapR-c-box-b-right ul input').each(function (index) {
                selectfield.push($(this).val());
            })
            if ($("#timecheck").attr("checked") == "checked") {
                timecheck = 1;
            }
        }
        var datastr = { "papertype": paperType, "field": selectfield.toString(), "timecheck": timecheck, "sysid": $("#dbid").val() }
        $.ajax({
            type: "POST",
            url: "@Html.Raw(Url.Action("UpdateCmsDataBase", "Admin_Submit"))",
            contentType: "application/json",
            data: JSON.stringify(datastr),
            success: function (msg) {
                if (msg == "True") {
                    messageAlert("操作成功！");
                    closeSubmit();
                    ajaxLoad(this, '@Html.Raw(Url.Action("SubmitNumber", "Admin_Submit"))');
                   
                }
                else {
                    messageAlert("操作失败！");
                }
            },
            error: function (e)
            { }
        })

    }
    $(function () {
        $("input[name='type']").bind("click", function () {
            if ($("input[name='type']:checked").val() == 2) {
                $(".talkDivBgField").hide();
            }
            else {
                $(".talkDivBgField").show();
            }
        })
    })

</script>
<div class="wrapR-c">
    <input type="hidden" id="dbid" name="dbid" />
    <table width="100%" cellspacing="0" cellpadding="0" border="0" class="table table-grey">
        <thead>
            <tr class="thead">
                <th class="tdnum">序号</th>
                <th>数据库名称</th>
                <th>命名方式</th>
                <th>选择字段</th>
                <th>是否加时间序列</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @{if (ViewBag.DbList != null)
              {
                  int sortno = ViewBag.PageSize * (ViewBag.PageNow - 1) + 1;
                  foreach (SYS_CMS_DATABASE item in ViewBag.DbList)
                  {
                      string str = "even";
                      if (sortno % 2 == 0)
                      {
                          str = "odd";
                      }
                <tr class='@str'>
                    <td>@sortno</td>
                    <td>@Html.Raw(ColumnAliasHelper.SubContent(item.DatabaseName, item.DatabaseName.Length))</td>
                    <td>
                        @{
                      string type = "";
                      if (item.PaperType == "0")
                      {
                          type = "保留原文件名";
                      }
                      else if (item.PaperType == "1")
                      {
                          type = "原文件名+时间序列命名";
                      }
                      else
                      {
                          type = "选择字段";

                      }     
                        }
                        @type
                    </td>
                    <td>
                        <a title="@item.PaperFieldValue" style="text-decoration:none;cursor:default;"> 
                       @Html.Raw(ColumnAliasHelper.SubContent(item.PaperFieldValue,40))</a>
                    </td>
                    <td class='tc'>
                        @{
                      string strno = "";
                      if (item.DatetimeFlag == "0")
                      {
                          strno = "否";
                      }
                      else
                      {
                          strno = "是";
                      }
                        }
                        @strno
                    </td>

                    <td class="tc">
                        <a onclick="modityInfo('@item.SysID','@item.DatabaseCode','@item.PaperFieldValue','@item.PaperType','@item.DatetimeFlag')" href="javascript:void(0)">编辑</a>
                    </td>
                </tr>
                      sortno = sortno + 1;
                  }
              }

            }
        </tbody>
    </table>
    @*//分页*@
    <div class="pagenav pagenav-02">
        @*上一页*@
        @if (ViewBag.TotalPage > 0)
        {
            if (ViewBag.PageNow != 1)
            {
                int thispage = ViewBag.PageNow - 1;
            <a href="javascript:void(0);" class="page-prev" onclick="searchPageNew('@thispage')" >上一页</a>
            }
            else
            {
            <a href="javascript:return false;"  onclick="return false" class="page-prev disable">上一页</a>
            }
@*循环初始化页码*@
            foreach (string numpage in ViewBag.PageList)
            {
                if (numpage != "0")
                {
                    int m = int.Parse(numpage);
                    if (m == ViewBag.PageNow)
                    {
            <a href="javascript:void(0);" class="active" onclick="searchPageNew('@numpage')">@numpage</a>
                    
                    }
                    else
                    {
            <a href="javascript:void(0);" onclick="searchPageNew('@numpage')">@numpage</a>
                    }

                }
                else
                {
            <i class="iconfont icon-dian2"></i>
                }

            }
@*下一页*@
            if (ViewBag.TotalPage > 0 && ViewBag.PageNow != ViewBag.TotalPage)
            {
                int nextpage = ViewBag.PageNow + 1;
            <a href="javascript:void(0);" class="page-next" onclick="searchPageNew('@nextpage')" >下一页</a>
            }
            else
            {
            <a href="javascript:return false;"  onclick="return false" class="page-prev disable">下一页</a>
            }
        }
        @if (ViewBag.DbList == null || ViewBag.DbList.Count == 0)
        {
            <label>暂无数据！</label>
        
        }
        else
        {
          
            <label>共 </label>
            <label>@ViewBag.Count </label>
            <label>条数据 </label>
        }
    </div>
</div>

<!--talkDiv弹出层(不带图片，宽550)-->
<div class="talkDiv talkDivTr talkW-550 form-h submitnum" style='margin-top: -200px; display: none'>
    <div class="talkDiv-title">
        <span>数字对象配置方式</span>
        <a class="icon icon-close" title="关闭" onclick="closeSubmit()" href="javascript:void(0);"><i class="iconfont icon-error3"></i></a>
    </div>
    <div class="talkDiv-body talkDiv-body1">
        <div class="f-gp">
            <label class="f-label">
                <input type="radio" name="type" class="f-radio" checked="checked" value="0">保留原来的上传文件名</label>
        </div>

        <div class="f-gp">
            <label class="f-label">
                <input type="radio" name="type" class="f-radio" value="1">将上传的文件名+时间序列命名,保证唯一性</label>
        </div>
        <div class="f-gp">
            <label class="f-label">
                <input type="radio" name="type" class="f-radio" value="2">取数据库的非空字段(CHAR,VCHAR类型)内容来作为文件名,选择字段(仅网页提交用)</label>
        </div>

        <div class="clearfix posr wrapR-c2-in" style="width: 450px;">
            <div class="wrapR-c-box wrapR-c-l fl posr" style="overflow-y: visible; width: 200px; height: 230px">
                <div class="wrapR-c-box-t">待选字段</div>
                <div class="wrapR-c-box-b-left" style="overflow-y: scroll; height: 160px">
                    <ul>
                    </ul>
                    <div class="f-ct wrapR-c-box-footer posa" style="margin-left: 0px">
                        <label class="f-label ml10">
                            <input type="checkbox" class="f-checkbox-left" onclick="leftCheckAll(this)" />全选</label>
                    </div>
                </div>

            </div>
            <div class="wrapR-c-m tc posa" style="text-align: left; margin-left: -7px">
                <a class="iconfont-s iconfont-right-triangle-s" onclick="rightMove('.wrapR-c-box-b-left','.wrapR-c-box-b-right')"></a>

            </div>
            <div class="fr posr">
                <div class='wrapR-c-box wrapR-c-r wrapR-c-r-l' style="overflow-y: visible; width: 200px; height: 230px">
                    <div class="wrapR-c-box-t">已选字段</div>
                    <div class="wrapR-c-box-b-right" style="overflow-y: scroll; height: 160px">
                        <ul class="ulfield">
                        </ul>
                        <div class="f-ct wrapR-c-box-footer posa clearfix" style="margin-left: 0px">
                            <label class="f-label ml10 fl">
                                <input type="checkbox" class="f-checkbox-right" onclick="rightCheckAll(this)">全选</label>
                            <button class="btn btn-s btn-warn-f fr deleteright" onclick="deleteright()">删除</button>
                        </div>
                    </div>
                </div>

                <div class="wrapR-c-r-r form-h posa" style="top: 10px; left: 215px">
                    <div style="padding-bottom: 50px">
                       <a title="移至最顶部" onclick=" movefirst(this)" class="iconfont-s iconfont-upest-s"></a>
                    <br />
                    <a title="上移" onclick="moveablove(this)" class="iconfont-s iconfont-up-s"></a>
                    <br />
                    <a title="下移" onclick="movedown(this)" class="iconfont-s iconfont-down-s"></a>
                    <br />
                    <a title="移至最底部" onclick="movelast(this)" class="iconfont-s iconfont-downest-s"></a>
                    </div>

                </div>
            </div>

            <div class="f-gp">
                <label class="f-label">
                    <input type="checkbox" id="timecheck" />后接时间序列</label>
            </div>
        </div>

        <div class="talkDivBgField" style="background-color: #000; opacity: 0.1; z-index: 999; filter: alpha(opacity=15); width: 100%; height: 280px; position: absolute; top: 180px; left: 0; bottom: 90px;">
            @*遮罩层，点击所有分类时*@
        </div>


        <div class="f-gp" style="padding-top: 20px">
            <div class="f-ct" style="margin-left: 150px">
                <a href="javascript:void(0);" class="btn btn-m btn-prim-f btn-submit" onclick="saveSubmitNumber()">保存</a>
                &#12288;<a href="javascript:void(0);" class="btn btn-m btn-submit btn-defa-f" onclick="closeSubmit()">取消</a>
            </div>
        </div>

    </div>
</div>



